﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ServerForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            string servicename = this.textBox5.Text.Trim();
            if (!string.IsNullOrEmpty(servicename))
            {
                ServiceManager sm = new ServiceManager();
                ServerForm.ServiceManager.EnumServiceStatus es = sm.GetServiceStatus(servicename);
                switch (es)
                {
                    case ServerForm.ServiceManager.EnumServiceStatus.Stopped:
                        this.labState.Text = "停止中";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.StartPending:
                        // 開始中
                        this.labState.Text = "开始中";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.Running:
                        // 运行中
                        this.labState.Text = "运行中";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.StopPending:
                        // 停止中
                        this.labState.Text = "停止中";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.PausePending:
                        // 一時中断中
                        this.labState.Text = "一时中断中";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.Paused:
                        // 一時中断
                        this.labState.Text = "一时中断";
                        break;
                    case ServerForm.ServiceManager.EnumServiceStatus.ContinuePending:
                        // 保留中
                        this.labState.Text = "保留中";
                        break;
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string filepath = this.textBox1.Text.Trim();
            string sname = this.textBox6.Text.Trim();
            if (!string.IsNullOrEmpty(filepath))
            {
                 IDictionary mySavedState = new Hashtable();
                ServiceManager sm = new ServiceManager();
                sm.InstallService(mySavedState, filepath, sname);

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string filepath = this.textBox1.Text.Trim();
            string sname = this.textBox6.Text.Trim();
            if (!string.IsNullOrEmpty(filepath))
            {
                ServiceManager sm = new ServiceManager();
                sm.UnInstallService(filepath, sname);
            }
        }
    }
}
